# 链式调用

import os

from langchain_core.messages import SystemMessage, HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_deepseek import ChatDeepSeek

os.environ["LANGCHAIN_TRACING_V3"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "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"

deepseek_api_key = "sk-1dd16a258a73428d910d38c782e1c94f"

# 1、创建模型
model = ChatDeepSeek(
    api_key=deepseek_api_key,
    # deepseek-reasoner : DeepSeek-R1
    model="deepseek-chat",
    temperature=0.7,
    max_tokens=1024
)

# 2、准备提示语
prompt = [
    SystemMessage(content="你是一个助手，请用中文回答问题。"),
    HumanMessage(content="你好，你是做什么的？")
]

# 3、获取响应结果
response = model.invoke(prompt)

# 直解析内容
parser = StrOutputParser()

# 转换为json 打印
# result = response.model_dump_json()
# print(result)

# 4、得到链
chain = model | parser

# 直接使用chain调用
result = chain.invoke(prompt)
print(result)
